﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TargetCalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonButtom_Click(object sender, EventArgs e)
        {

            if (textHead.Text == "" || textNeck.Text == "")
            {
                MessageBox.Show("填写内容不能为空");
                return;
            }


            decimal dHead = Convert.ToDecimal(textHead.Text);
            decimal dNeck = Convert.ToDecimal(textNeck.Text);
            decimal dTarget;
            if ( dHead > dNeck )
            {
                MessageBox.Show("底背离应该计算底部");
            }
            dTarget = ((dNeck - dHead) * dNeck / dHead) + dNeck;
            labelTarget.Text = dTarget.ToString();
            if (textNow.Text == "")
            {
                decimal dDst;
                decimal dNow = Convert.ToDecimal(textNow.Text);
                dDst =  (dTarget-dNow)/dNow*100;
                labelDst.Text = dDst.ToString();
            }
        }

        private void buttonTop_Click(object sender, EventArgs e)
        {
            if (textHead.Text == "" || textNeck.Text == "")
            {
                MessageBox.Show("填写内容不能为空");
                return;
            }


            decimal dHead = Convert.ToDecimal(textHead.Text);
            decimal dNeck = Convert.ToDecimal(textNeck.Text);
            decimal dTarget;
            if (dHead > dNeck)
            {
                MessageBox.Show("底背离应该计算底部");
            }
            dTarget = dNeck - ((dHead - dNeck) * dNeck / dHead);
            labelTarget.Text = dTarget.ToString();
            if (textNow.Text == "")
            {
                decimal dDst;
                decimal dNow = Convert.ToDecimal(textNow.Text);
                dDst = (dNow - dTarget) / dNow * 100;
                labelDst.Text = dDst.ToString();
            }
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

    }
}
